<?php
//img

//$path = 'image.jpg';
//$fp = fopen($path, 'rb');  // 以二进制形式打开文件
//$content = fread($fp, filesize($path)); // 读取文件内容
//fclose($fp);
//$content = base64_encode($content);
//
//echo $content;
//echo "<br><br><br><br><br><br>";
//
//$contents = base64_decode($content);
//echo "<img src='data:image/png;base64,{$content}'>";
//
//$myfile = fopen("test.jpg", "w");
//fwrite($myfile, $contents);
//fclose($myfile);

//$path="/phptest/base64/xls"; //要创建的目录
//$mode=0755; //创建目录的模式，即权限.
//createdirlist($path,$mode);//测试

$path = 'yuan.xls';
$fp = fopen($path, 'rb');  // 以二进制形式打开文件
$content = fread($fp, filesize($path)); // 读取文件内容
fclose($fp);
$content = base64_encode($content);
echo $content;
$contents = base64_decode($content);
$myfile = fopen('test.xls', 'w');
fwrite($myfile, $contents);
fclose($myfile);

echo "<br>";
echo $_SERVER['SCRIPT_NAME'];
echo "<br>";
echo $_SERVER['DOCUMENT_ROOT'];


function createdirlist($path,$mode){
   if (is_dir($path)){
   //判断目录存在否，存在不创建
     echo "目录'" . $path . "'已经存在";
  //已经存在则输入路径
   }else{ //不存在则创建目录
      $re=mkdir($path,$mode,true);
  //第三个参数为true即可以创建多级目录
     if ($re){
       echo "目录创建成功";//目录创建成功
     }else{
       echo "目录创建失败";
      }
     }
  }

